import type { StorageKey, StorageType } from './type';

export function setItem(key: StorageKey, value: string, type: StorageType = 'session') {
    const storage = type === 'session' ? sessionStorage : localStorage;
    storage.setItem(key, value);
}

export function getItem(key: StorageKey, defaultValue: string, type: StorageType = 'session'): string {
    const storage = type === 'session' ? sessionStorage : localStorage;
    return storage.getItem(key) || defaultValue;
}

export function removeItem(key: StorageKey, type: StorageType = 'session') {
    const storage = type === 'session' ? sessionStorage : localStorage;
    storage.removeItem(key);
}

export function clear(type: StorageType = 'session') {
    const storage = type === 'session' ? sessionStorage : localStorage;
    storage.clear();
}
